package com.cy.lib.manager;

import android.app.Application;

import java.io.File;

/**
 * @author CY
 * @date 2014-11-24
 * @package com.src.zf.doudou
 */
public class StorageManager extends Manager {

    Application mApp;
    private String mAppRootDirName;

    public StorageManager(Application app) {
        mApp = app;
    }

    public static StorageManager getInstance() {
        return (StorageManager) Manager.getInstance().getLocalService(LocalService.STORAGE);
    }

    public void setAppRootDirectoryName(String name) {
        mAppRootDirName = name;
        File file = getAppRootDirectory();
        if (!file.exists()) {
            file.mkdirs();
        }
    }


    public boolean isReadable() {
        return android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
    }

    public File getExternalStorageDirectory() {
        return android.os.Environment.getExternalStorageDirectory();
    }

    /**
     * App根目录
     *
     * @return
     */
    public File getAppRootDirectory() {
        File file = new File(getExternalStorageDirectory(), mAppRootDirName);
        if (!file.exists()) {
            file.mkdirs();
        }
        return file;
    }


}
